package com.huaixia18.systemnotice.controller;

import com.huaixia18.systemnotice.domain.PrivateMessage;
import com.huaixia18.systemnotice.domain.PrivateChat;
import com.huaixia18.systemnotice.service.PrivateChatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/private-chat")
public class PrivateChatController {

    @Autowired
    private PrivateChatService privateChatService;

    // 创建或获取聊天室接口
    @GetMapping("/{user1Id}/{user2Id}")
    public PrivateChat getOrCreatePrivateChat(@PathVariable Long user1Id, @PathVariable Long user2Id) {
        return privateChatService.getOrCreatePrivateChat(user1Id, user2Id);
    }

    // 发送私信接口
    @PostMapping("/send")
    public void sendPrivateMessage(@RequestBody PrivateMessage message) {
        privateChatService.sendPrivateMessage(message);
    }

    // 获取用户私信列表接口
    @GetMapping("/user/{recipientId}")
    public List<PrivateMessage> getPrivateMessages(@PathVariable Long recipientId) {
        return privateChatService.getPrivateMessages(recipientId);
    }

}
